<?php

class Silk_Controller_Admin_Action extends Silk_Controller_Action {

    protected $_layout = 'administration';

    public function init(){
	parent::init();
	$this->view->dashboard_section = strtolower($this->_request->getControllerName());

	$breadcrumbs = array(array('label' => Silk::Translate('Dashboard'),'href' => $this->resolveRoute('dashboard') ));
	$this->view->breadcrumbs = $breadcrumbs;
    }

    protected function initPaginatorParams($pNamespace, $pDefaultSort=null, $pDefaultOrder='ASC', $pDefaultLimit=25, $pDefaultOffset=null){

	$session = Silk::getSession();

	if (isset($session->paginator_namespace)){
	    if ($session->paginator_namespace != $pNamespace){
		unset($session->limit);
		unset($session->offset);
		unset($session->page);
		unset($session->sort);
		unset($session->order);
		$session->paginator_namespace = $pNamespace;
	    }
	} else
	    $session->paginator_namespace = $pNamespace;

	if ($this->_request->has('limit'))
	    $session->limit = $this->_getParam('limit');
	else
	    if (!isset($session->limit))
		$session->limit = $pDefaultLimit;

	if ($this->_request->has('offset'))
	    $session->offset = $this->_getParam('offset');
	else
	    if (!isset($session->offset))
		$session->offset = null;

	if ($this->_request->has('page'))
	    $session->page = $this->_getParam('page');
	else
	    if (!isset($session->page))
		$session->page = 1;

	if ($this->_request->has('sort'))
	    $session->sort = $this->_getParam('sort');
	else
	    if (!isset($session->sort))
		$session->sort = $pDefaultSort;

	if ($this->_request->has('order'))
	    $session->order = $this->_getParam('order');
	else
	    if (!isset($session->order))
		$session->order = $pDefaultOrder;

	$this->view->sort = $session->sort;
	$this->view->order = $session->order;
	$this->view->limit = $session->limit;
	$this->view->page = $session->page;
    }

    protected function appendBreadcrumbs($pLabel, $pHref=null){
	$breadcrumbs = $this->view->breadcrumbs;
	$breadcrumbs[] = array('label' => $pLabel, 'href' => ($pHref) ? $pHref : $this->_current_uri);
 	$this->view->breadcrumbs = $breadcrumbs;
    }
}

?>